const mongoose = require("mongoose")

const Schema = mongoose.Schema
const {Mixed,ObjectId} = Schema.Types

const MovieShema = new Schema({
    doubanID:{
        type:String,
        unique:true,
        required:true
    },
    category:[{
        type:ObjectId,
        ref:"Category"
    }],
    rate:Number,
    title:String,
    sumary:String,
    video:String,
    poster:String,
    cover:String,

    rawTitle:String,
    pubData:Mixed,
    movieType:[String],
    year:Number,

    videoKey:String,
    posterKey:String,
    coverKey:String,

    tags:Array,

    meta:{
        createdAt:{
            type:Date,
            default:Date.now(),
        },
        upDatedAt:{
            type:Date,
            default:Date.now(),
        }
    }
})

MovieShema.pre('save',function(next) {
    if(this.isNew){
        this.meta.createdAt = this.meta.upDatedAt = Date.now()
    }else{
        this.meta.upDatedAt = Data.now()
    }
    next()
})

mongoose.model('Movie',MovieShema)